package com.juc.completionService.completionService3;

import java.util.concurrent.Callable;
import java.util.concurrent.CompletionService;
import java.util.concurrent.ExecutorCompletionService;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class Run {
/**
 * poll 获取并移除表示下一个已完成任务的Future，如果不存在这样的任务
 * 则返回null， 方法poll无阻塞效果
 */
	@SuppressWarnings("unchecked")
	public static void main(String[] args) {
		ExecutorService executorService = Executors.newCachedThreadPool();
		CompletionService csRef = new ExecutorCompletionService<>(executorService);
		for (int i = 0; i < 1; i++) {
			csRef.submit(new Callable<String>() {

				@Override
				public String call() throws Exception {
				    Thread.sleep(3000);
				    System.out.println("3秒过后了");
					return "高洪岩3秒";
				}
			});
		}
		
		for (int i = 0; i < 1; i++) {
			System.out.println(csRef.poll());
		}
		
	}
}
